#include <bits/stdc++.h>
using namespace std;
const int N = 1005;

int b[N];
int fa[N];
int n, m;
int find(int x)
{
    if (fa[x] == x)
        return x;
    fa[x] = find(fa[x]);
    return fa[x];
}
void add(int x, int y)
{
    x = find(x);
    y = find(y);
    fa[x] = y;
}
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        fa[i] = i;
    char op;
    int x, y;
    memset(b, 0, sizeof(b));
    for (int i = 0; i < m; i++)
    {
        cin >> op >> x >> y;
        if (op == 'E')
        {
            if (b[x] == 0)
            {
                b[x] = y;
            }
            else
            {
                add(b[x], y);
            }
            if (b[y] == 0)
            {
                b[y] = x;
            }
            else
            {
                add(b[y], x);
            }
        }
        else if (op == 'F')
        {
            add(x, y);
        }
    }
    int sum = 0;
    bool visit[N];
    memset(visit, false, sizeof(visit));
    for (int i = 1; i <= n; i++)
    {
        int f = find(i);
        if (!visit[f])
        {
            visit[f] = true;
            sum++;
        }
    }
    cout << sum;
    return 0;
}
